﻿using HKB.Common;
using HKB.Web;
using HKB.Web.Admin;
using System;
using System.Collections;
using System.Data;
using System.Text;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;

public partial class Admin_Admin_Lable : Admin, IRequiresSessionState
{
    private LabelBll _lb = null;
    private bool tag = true;
    private ArrayList al = new ArrayList();
    private IDbDataParameter[] param = null;
    private string wherestr = "";
    protected LabelBll lb
    {
        get
        {
            LabelBll lb;
            if (this._lb == null)
            {
                this._lb = new LabelBll(this.conn);
                lb = this._lb;
            }
            else
            {
                lb = this._lb;
            }
            return lb;
        }
    }
    protected DefaultProfile profile
    {
        get
        {
            return (DefaultProfile)this.Context.Profile;
        }
    }
    protected global_asax applicationInstance
    {
        get
        {
            return (global_asax)this.Context.ApplicationInstance;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(56))
        {
            base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "Lable");
            base.WriteRightErrMsg();
        }
        if (!base.admin.CheckAdminPower(58))
        {
            this.DeleteALL.Visible = false;
        }
        this.LableManage.Text = this.ShowLabelType();
        if (!string.IsNullOrEmpty(Fetch.Get("action")) && Fetch.Get("action") == "updateLabel")
        {
            int labelID = int.Parse(Fetch.Get("id"));
            this.lb.CreateStaticLabel(labelID);
        }
        if (!base.IsPostBack)
        {
            this.BindList();
        }
    }
    protected void BindList()
    {
        this.QuestString();
        if (this.al.Count > 0)
        {
            this.param = new IDbDataParameter[this.al.Count];
            this.al.CopyTo(this.param, 0);
        }
        if (this.param != null)
        {
            this.GridView1.DataSource = this.conn.GetDataTable("Select * From [HL_Label] " + this.wherestr + "  order by  UpdateTime DESC, ID DESC", this.param);
        }
        else
        {
            this.GridView1.DataSource = this.lb.GetAllLabel();
        }
        this.GridView1.DataBind();
    }
    protected void QuestString()
    {
        string text = Fetch.Get("type", "string");
        if (text != string.Empty)
        {
            this.wherestr += "and [Type] = @Type ";
            this.al.Add(this.conn.CreateParameter("@Type", DbType.String, text));
        }
        string text2 = Fetch.Get("keyword", "string");
        if (text2 != string.Empty && this.tag)
        {
            this.Txtkeyword.Text = text2;
        }
        else
        {
            text2 = this.Txtkeyword.Text;
        }
        if (text2 != string.Empty)
        {
            this.wherestr += "and [Name] like '%'+ @Name +'%' ";
            this.al.Add(this.conn.CreateParameter("@Name", DbType.String, text2));
        }
        if (this.wherestr != string.Empty)
        {
            this.wherestr = "and" + this.wherestr;
            this.wherestr = this.wherestr.Replace("andand", "where");
        }
    }
    protected void Sreach_OnClick(object sender, EventArgs e)
    {
        this.tag = false;
        this.BindList();
    }
    public string ShowLabelType()
    {
        DataTable labelType = this.lb.GetLabelType();
        StringBuilder stringBuilder = new StringBuilder();
        if (labelType.Rows.Count > 0)
        {
            for (int i = 0; i < labelType.Rows.Count; i++)
            {
                stringBuilder.Append(string.Concat(new string[]
				{
					"<a href=\"Admin_Lable.aspx?type=",
					base.Server.UrlEncode(labelType.Rows[i]["Type"].ToString()),
					"\">",
					labelType.Rows[i]["Type"].ToString(),
					"</a> | "
				}));
            }
        }
        return stringBuilder.ToString();
    }
    protected void Delete_Click(object sender, CommandEventArgs e)
    {
        if (!base.admin.CheckAdminPower(58))
        {
            base.WriteLog("Delete", Language.GetAdminMsg("Log/Access", e.CommandArgument.ToString()), "Lable");
            base.WriteRightErrMsg();
        }
        if (e.CommandArgument != null)
        {
            this.lb.DeleteLabel(int.Parse(e.CommandArgument.ToString()));
            this.BindList();
        }
    }
    protected void DeleteALL_OnClick(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(58))
        {
            base.WriteLog("Delete", Language.GetAdminMsg("Log/Access", Fetch.GetOrPost("IDs")), "Lable");
            base.WriteRightErrMsg();
        }
        string orPost = Fetch.GetOrPost("IDs");
        if (orPost != string.Empty)
        {
            if (Text.CheckNumList(orPost, ','))
            {
                this.conn.Execute("Delete From [HL_Label] Where ID in(" + orPost + ")");
                this.BindList();
            }
        }
    }
    protected void CopyButton_OnCommodn(object sender, CommandEventArgs e)
    {
        if (!base.admin.CheckAdminPower(59))
        {
            base.WriteLog("Check", Language.GetAdminMsg("Log/Access", "0"), "Lable");
            base.WriteRightErrMsg();
        }
        if (this.lb.CopyLabelByID(int.Parse(e.CommandName)))
        {
            this.BindList();
        }
    }
    protected void GridView1_DataBound(object sender, EventArgs e)
    {
        bool flag = base.admin.CheckAdminPower(58);
        bool flag2 = base.admin.CheckAdminPower(59);
        foreach (GridViewRow gridViewRow in this.GridView1.Rows)
        {
            if (!flag)
            {
                gridViewRow.Cells[4].Controls[1].Visible = false;
            }
            if (!flag2)
            {
                gridViewRow.Cells[4].Controls[0].Visible = false;
                gridViewRow.Cells[4].Controls[3].Visible = false;
            }
        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.BindList();
        this.GridView1.PageIndex = e.NewPageIndex;
        this.GridView1.DataBind();
    }
    protected void GoConetent(object sender, CommandEventArgs e)
    {
        string text = "Admin_LabelTemplateStatic.aspx";
        LabelBll labelBll = new LabelBll(this.conn);
        DataTable labelDefineByLabelID = labelBll.GetLabelDefineByLabelID(Convert.ToInt32(e.CommandArgument));
        string a = labelDefineByLabelID.Rows[0]["LabelDataType"].ToString();
        if (a != "static")
        {
            text = "Admin_LabelTemplate.aspx";
        }
        base.Response.Redirect(string.Concat(new object[]
		{
			text,
			"?action=modify&id=",
			e.CommandArgument,
			"&name=",
			e.CommandName
		}));
    }
}
